<?php
namespace app\model;


class UserModel extends BaseModel
{
    public $table='zkhb_user';

    protected function initialize()
    {
        parent::initialize();
    }

    /**
     * @param $where
     * @param string $orderby
     * @return array|bool
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getOne($where,$orderby='') {
        $res = $this->where($where)->find();
        if(!$res) {
            return false;
        }
        return $res->toArray();
    }

    /**
     * @param $where
     * @param string $orderby
     * @return array|bool
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getAll ($where,$orderby='id desc') {
        $res = $this->where($where)->order($orderby)->select();
        if($res->isEmpty()) {
            return false;
        }
        return $res->toArray();
    }

    /**
     * 分页查询
     * @param $where
     * @param int $page
     * @param int $size
     * @param string $orderby
     * @return array|bool
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getPage ($where,$page=1,$size=20,$orderby='') {
        $res = $this->where($where)->page($page,$size)->select();
        if($res->isEmpty()) {
            return false;
        }
        return $res->toArray();
    }

    /**
     * @param $where
     * @return int|string
     * @throws \think\Exception
     */
    public function getCount ($where) {
        return $res = $this->where($where)->count();
    }

}